package cn.jtcoding.springframework.aop.proxy.factory;

import cn.jtcoding.springframework.aop.aspect.AspectInfo;
import cn.jtcoding.springframework.aop.proxy.AopProxy;
import cn.jtcoding.springframework.aop.proxy.CglibDynamicProxy;
import cn.jtcoding.springframework.aop.proxy.JdkDynamicProxy;

import java.util.List;

public class DefaultAopProxyFactory implements AopProxyFactory {
    @Override
    public AopProxy createAopProxy(Object targetObj, List<AspectInfo> aspectInfoList) throws Exception {
        Class<?> clazz = targetObj.getClass();
        if (clazz.isInterface() || clazz.getSuperclass().isInterface() || clazz.getInterfaces().length > 0) {
            return new JdkDynamicProxy(targetObj, aspectInfoList);
        }
        return new CglibDynamicProxy(targetObj, aspectInfoList);
    }
}
